package com.tools.cleanmaster.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.tools.cleanmaster.CleanApplication;
import com.tools.cleanmaster.R;

/**
 * Created by wuyanfei on 16/4/26.
 */
public class FrequencyChooseDialog extends Dialog {

    private final Context mContext;

    public FrequencyChooseDialog(Context context) {
        super(context, R.style.MyTheme_FeedDialog);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_choose_frequency);

        int frequency = CleanApplication.getInstance().getAutoCleanManager().getAutoCleanFrequency();
        RadioGroup radioGroup = findViewById(R.id.frequency_radio_group);
        switch (frequency) {
            case 6:
                radioGroup.check(R.id.frequency_6hour);
                break;
            case 12:
                radioGroup.check(R.id.frequency_12hour);
                break;
            case 24:
                radioGroup.check(R.id.frequency_1day);
                break;
            case 3 * 24:
                radioGroup.check(R.id.frequency_3day);
                break;
            case 7 * 24:
                radioGroup.check(R.id.frequency_7day);
                break;
            default:
                break;
        }
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int frequency;
                if (checkedId == R.id.frequency_7day) {
                    frequency = 7 * 24;
                } else if (checkedId == R.id.frequency_3day) {
                    frequency = 3 * 24;
                } else if (checkedId == R.id.frequency_1day) {
                    frequency = 24;
                } else if (checkedId == R.id.frequency_12hour) {
                    frequency = 12;
                } else {
                    frequency = 6;
                }
                CleanApplication.getInstance().getAutoCleanManager().setAutoCleanFrequency(frequency);
                dismiss();
            }
        });
    }
}
